import java.awt.*;
import java.util.*;
import danlib.IVec2;

/*
	Terrain is the landscape, and handles the generation and the maintenance of it
	as it is destroyed in game.
*/
public class Terrain
{
	int width = 800;
	int height = 600;
	
	ArrayList<IVec2> ground = new ArrayList<IVec2>();
	
	public Terrain()
	{
		//GENERATE a set of random heights
		for( int x = 0; x <= width; x += width/20 )
		{
			ground.add( new IVec2( x, (int)(Math.random() * height-100) + 100 ) );
		}
		
		//SMOOTH the heights by taking the average of neighbors
		for( int j = 0; j < 3; j++ )
		{
			for( int i = 1; i < ground.size() - 1; i++ )
			{
				ground.get(i).y = (ground.get(i).y + ground.get(i-1).y + ground.get(i+1).y)/3;
			}
		}
	}
	
	public void draw( Graphics2D g2 )
	{
		//DRAW lines from current point to next
		for( int i = 0; i < ground.size() - 1; i++ )
		{
			g2.drawLine( ground.get(i).x, ground.get(i).y, ground.get(i+1).x, ground.get(i+1).y );
		}
	}
}